open Printf
open Arg
open String
open List
open Usage
open InsertSort
open Camlcoq


let rec print_list = function
  [] -> ()
| e::l -> print_int (Int32.to_int e) ; print_string " " ; print_list l;;

let rec int32list_of_strint32list strlist =
  match strlist with
  [] -> []
  | head :: tail -> (Int32.of_string head) :: int32list_of_strint32list tail;;

let cmdSort strInt32List =
    let strlist = split_on_char ',' strInt32List in
    let int32list = int32list_of_strint32list strlist in
    let tmplist = coqlistz_of_camllistint int32list in
    let coqlist = sort tmplist in
    let result = camllistint_of_coqlistz coqlist in
    print_list result;;

(* 正常退出: 所有的通道都已写入且关闭 *)
let main()=
  if (Array.length Sys.argv)!=2 then
    print_endline usageMsg
  else
    Arg.parse [] cmdSort usageMsg;;


main();;
print_endline "";;
